<?php


require_once(DIR_LIB."VsUsers".DIR_SEP."vsuser.php");

class VsCustomer extends VsUser {

	protected $_id = 0;
	protected $_userId = 0;	// registered User

	private $_billingAddress = NULL;
	private $_shippingAddress = NULL;

	static function makeUsers($sqlTableAuth, $sqlTable) {
		$auth = VsAuth::Instance();
		if($auth->level()<=5)
			return array();

		$db = VsDatabase::Instance();
		$listUsers = array();

		$q = "SELECT * FROM `".$sqlTable."`";

		$res = $db->query($q);
		while($rUser = @mysql_fetch_object($res)) {

			$authData = VsAuthData::makeUserById($rUser->auth_id, $sqlTableAuth);
			if($authData->level() >= $auth->level())
				continue;
			
			$user = new VsUser($sqlTable);
			$user->_authData = $authData;

			// Personal Data
			$user->_userTitle = $rUser->title;
			$user->_userFirstName = $rUser->name;
			$user->_userSecondName = $rUser->second_name;
			$user->_userFamilyName = $rUser->family;

			// Contact Data
			$user->_userMail = $rUser->email;
			
			array_push($listUsers, $user);
		}

		return $listUsers;
	}
	//=========================================================================================

	static function makeUserById($id, $sqlTableAuth, $sqlTable) {
		$user = new VsUser($sqlTable);

		$auth = VsAuth::Instance();
		if(($auth->level()<=5) && $auth->id()!=$id)
			return $user;

		$db = VsDatabase::Instance();
		$q = "SELECT * FROM `".$sqlTable."` WHERE id=".$id;
		$res = $db->query($q);

		$rUser = @mysql_fetch_object($res);
		if($rUser){
			$authData = VsAuthData::makeUserById($rUser->auth_id, $sqlTableAuth);

			$user->_authData = $authData;

			// Personal Data
			$user->_userTitle = $rUser->title;
			$user->_userFirstName = $rUser->name;
			$user->_userSecondName = $rUser->second_name;
			$user->_userFamilyName = $rUser->family;

			// Contact Data
			$user->_userMail = $rUser->email;
		}

		return $user;
	}
	//=========================================================================================

	function VsCustomer($sqlTable = 'custommers') {
		parent::__construct($sqlTable);
	}
	//=========================================================================================

	function authData() {

	}
	//=========================================================================================

	function billingAddress() {

	}
	//=========================================================================================

	function shippingAddress() {

	}
	//=========================================================================================

};

?>
